<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="数据日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dataDt">
              <j-date placeholder="请选择数据日期" v-model="model.dataDt"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金融机构代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jrjgdm">
              <a-input v-model="model.jrjgdm" placeholder="请输入金融机构代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="内部机构号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="nbjghm">
              <a-input v-model="model.nbjghm" placeholder="请输入内部机构号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款合同编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkthbm">
              <a-input v-model="model.dkthbm" placeholder="请输入贷款合同编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="贷款借据编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dkjjbm">
              <a-input v-model="model.dkjjbm" placeholder="请输入贷款借据编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否个体工商户贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfgtgshdk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否个体工商户贷款"
                v-model="model.sfgtgshdk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否小微企业主贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfxwqyzdk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否小微企业主贷款"
                v-model="model.sfxwqyzdk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否涉农贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfsmdk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否涉农贷款"
                v-model="model.sfsmdk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="涉农贷款类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="smdklx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择涉农贷款类型"
                v-model="model.smdklx"
                dict="llbb_param_config,name,code"
                pidValue="4816b09a83884d61a4df7f9fe0002789"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否精准扶贫贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfjzfpdk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否精准扶贫贷款"
                v-model="model.sfjzfpdk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否建档立卡贫困人口贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfjdlkfkrkdk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否建档立卡贫困人口贷款"
                v-model="model.sfjdlkfkrkdk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否地方政府融资平台贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfdfzfrzpddk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否地方政府融资平台贷款"
                v-model="model.sfdfzfrzpddk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="地方融资平台按法律性质分类类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dfrzptaflxzfllx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择地方融资平台按法律性质分类类型"
                v-model="model.dfrzptaflxzfllx"
                dict="llbb_param_config,name,code"
                pidValue="ffd4e639dd1546499a5b72b7e8825363"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="地方融资平台按隶属关系分类类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dfrzptalsgxfllx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择地方融资平台按隶属关系分类类型"
                v-model="model.dfrzptalsgxfllx"
                dict="llbb_param_config,name,code"
                pidValue="527b3dd04ecf4000bf2094e5800f6b9b"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="地方融资平台偿债资金来源分类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="dfrzptczzjlyfl">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择地方融资平台偿债资金来源分类"
                v-model="model.dfrzptczzjlyfl"
                dict="llbb_param_config,name,code"
                pidValue="d3a6acf29c804c53a20103cb3de602d9"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否保障性安居工程贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfbzxajgcdk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否保障性安居工程贷款"
                v-model="model.sfbzxajgcdk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="保障性安居工程贷款类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bzxajgcdklx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择保障性安居工程贷款类型"
                v-model="model.bzxajgcdklx"
                dict="llbb_param_config,name,code"
                pidValue="878917d622db44258f8b0bb014aa2703"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否绿色贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sflsdk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否绿色贷款"
                v-model="model.sflsdk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否创业担保贷款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sfcydbdk">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择是否创业担保贷款"
                v-model="model.sfcydbdk"
                dict="llbb_param_config,name,code"
                pidValue="1486500350999949313"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="创业担保贷款类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cydbdklx">
              <j-tree-select
                ref="treeSelect"
                placeholder="请选择创业担保贷款类型"
                v-model="model.cydbdklx"
                dict="llbb_param_config,name,code"
                pidValue="d358acadc5194752bed0abe8d8e5fb70"
                hasChildField="has_child"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'JsCdLoanSpeciForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 9 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/jsCdLoanSpeci/jsCdLoanSpeci/add",
          edit: "/jsCdLoanSpeci/jsCdLoanSpeci/edit",
          queryById: "/jsCdLoanSpeci/jsCdLoanSpeci/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.guid){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
